package com.lm.scau.dyb.activity.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.lm.scau.dyb.utils.HttpUtils;
import com.lm.scau.dyb.view.LoadingDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * Function:
 * auth：liming on 2016/8/4 15:51
 * mail：liming@wxchina.com
 */
public class BaseActivity extends AppCompatActivity {
    protected LoadingDialog dialog;
    protected RequestQueue mQueue;
    protected BaseActivity mActivity;
    protected HttpUtils httpUtils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = this;
        httpUtils = new HttpUtils(this);
        if (null == mQueue) {
            mQueue = Volley.newRequestQueue(getApplicationContext());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mQueue.stop();
    }

    public void loading() {
        if (null == dialog) {
            dialog = new LoadingDialog(this);
        }
        dialog.show();
    }

    public void dismiss() {
        if (null != dialog) {
            dialog.dismiss();
            dialog = null;
        }
    }

    public void setTip(String tip) {
        if (null == dialog) {
            dialog = new LoadingDialog(this);
        }
        dialog.setTipText(tip);
    }

    public void showToast(String msg) {
        if (null != msg && !"".equals(msg)) {
            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        }
    }
    /**
     * @param target 要跳转的类
     * @param bundle
     */
    public void startActivity(Class target, Bundle bundle) {
        Intent intent = new Intent(this, target);
        if (null != bundle) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    public RequestQueue getmQueue() {
        return mQueue;
    }
}
